<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->

@section('content')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>{{$name}}
                    </label>
                    <div class="layui-input-inline">
                        <input type="number" value="{{$money}}" readonly class="layui-input layui-disabled rechargeMoneyQ">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>充值金额：
                    </label>
                    <div class="layui-input-inline">
                        <input type="number" name="money" value="0" class="layui-input rechargeMoney" onkeyup="sumGoodsPrice()">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>充值后余额：
                    </label>
                    <div class="layui-input-inline rechargeMoneyH" style="line-height: 35px;color: #c82333">{{$money}}</div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <input type="hidden" value="{{ $store_id }}" name="store_id">
                    <input type="hidden" value="{{ $money_type }}" name="money_type">
                    <button class="layui-btn" lay-filter="add" lay-submit="">充值</button>
                </div>
            </form>
        </div>
    </div>
    <script>
        function sumGoodsPrice(){
            var money1 = Number($('.rechargeMoneyQ').val());
            var money2 = Number($('.rechargeMoney').val());
            $('.rechargeMoneyH').html(money1+money2);
        }

        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //监听提交
            form.on('submit(add)', function (data) {
                console.log(data);
                //发异步，把数据提交给php
                $.ajax({
                    type: 'POST',
                    url: '/admin/store/storeRecharge',
                    data: data.field,
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        // console.log(data);
                        if (data.code == 1) {
                            layer.alert("充值成功", {
                                    icon: 6
                                },
                                function () {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        } else {
                            layer.alert(data.msg)
                        }
                    },
                    error: function (xhr, type) {
                        alert('Ajax error!')
                    }
                });

                return false;
            });

        });
    </script>

@endsection
